var showBankPicker, balance;
var Main = function() {
	mui.init({
		swipeBack: false //启用右滑关闭功能
	});
	this.init();
	this.even();
	this.loadData();
};
Main.prototype = {
	init: function() {
		Util.checkLoginRedirect();
		var options = {  
			useEasing: true,
			  useGrouping: true,
			  separator: '',
			  decimal: '.',
			  prefix: '账户余额：',
			  suffix: '元',
			separator: ','
		};
		balance = Util.requestURL('balance');
		var totalEarnings = new CountUp("balance", 0.00, balance, 2, 1, options);
		totalEarnings.start();
	},
	even: function() {

		$("#btn-showBankSelect").on('tap', function() {
			if(showBankPicker) {
				showBankPicker.show(function(items) {
					$("#btn-showBankSelect").val(items[0].text);
					$("#bankCode").val(items[0].value);
				});
			}
		});
		$("#withdraw").on('tap', function() {
			var bankCode = $('#bankCode').val();
			if(!bankCode || bankCode == "") {
				mui.toast('请先绑定银行卡');
				return false;
			}
			var amount = $("#withdrawAmount").val();
			if(!Verify.isMoney(amount)) {
				mui.toast(Verify.isMoneyMsg);
				return false;
			}
			if(parseFloat(amount) <= 0) {
				Util.toast("提现金额必须大于0");
				return false
			};
			if(parseFloat(amount) > parseFloat(balance)) {
				Util.toast("提现金额不能大于可用余额");
				return false;
			}
			mui(this).button('loading');
			setTimeout(function() {
				mui(this).button('reset');
			}.bind(this), 5000);
			var url = server_url + "/pay/withdrawsPay.do";
			var param = {
				"isMobile": isMobile,
				"amount": amount,
				"pageType":1,
				"cardNo": $("#bankCode").val(),
				"accountid": storage.memberId
			}
			url = UrlHelper.customUrl(UrlHelper.urlEncode(param), url);
			//判定app
			if(isH5){
				window.open(url, '_system', 'location=yes');
			}else{
				url = encodeURIComponent(url);
				mui.openWindow({"url":"huifu.html?url=" + url + "&module=withdraw","id":"huifu-page"});
			}
		});
	},
	loadData: function() {
		var bankUrl = server_url + "/financePurchase/getBindBankListFinancePurchase.do";
		var param = {
			"isMobile": 2,
			"memberId": storage.memberId
		}
		$.getJSON(bankUrl, param, function(retData) {
			if(!retData.message) {
				$("#btn-showBankSelect").removeAttr("disabled");
				showBankPicker = new mui.PopPicker();
				showBankPicker.setData(retData);
				$("#btn-showBankSelect").val(retData[0].text);
				$("#bankCode").val(retData[0].value);
			}
		})
	}
}